layui.use(["element", 'layer', 'form', 'table'], function () {
  var element = layui.element,
    form = layui.form,
    layer = layui.layer,
    table = layui.table;
  form.on('select(AssetClass)', function (data) {
    vm.AssetClass = data.value;
  });
  setTable(vm.tableIns);
  // 重新渲染表格
  function setTable(data) {
    table.render({
      elem: '#table1',
      data: data,
      cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      cols: [
        [ //标题栏
          {
            field: 'id',
            title: 'ID',
            width: 50
          }, {
            field: 'AssetCode',
            title: '资产代码'
          }, {
            field: 'AssetName',
            title: '资产名称',
            minWidth: 120
          }, {
            field: 'AssetClass',
            title: '资产类别(大类)',
            width: 170
          }, {
            field: 'CompanyName',
            title: '企业名称'
          }, {
            field: 'amount1',
            title: '资产面额(万元)'
          }, {
            field: 'amount',
            title: '可投资金额(万元)'
          }, {
            fixed: 'right',
            title: '操作',
            toolbar: '#barDemo',
            width: 60
          }
        ]
      ]
    });
  }
  $('#searchBtn').on('click', function () {
    var AssetClass = $('#AssetClass').val();
    var CompanyName = vm.CompanyName;
    var Arr = [];
    if (AssetClass == 0) {
      if (CompanyName) {
        Arr = vm.defaultData.filter(function (item) {
          return item.CompanyName == CompanyName
        });
        vm.total(Arr);
      } else {
        Arr = vm.defaultData;
       // vm.totalVisible = false;
      }
      setTable(Arr);
    } else {
      if (CompanyName) {
        var Da = vm.defaultData.filter(function (item) {
          return item.AssetClass == AssetClass
        });
        Arr = Da.filter(function (item) {
          return item.CompanyName == CompanyName
        });
      } else {
        Arr = vm.defaultData.filter(function (item) {
          return item.AssetClass == AssetClass
        });
      }
      setTable(Arr);
      vm.total(Arr);
    }
  });
  //监听行工具事件
  table.on('tool(demo)', function (obj) {
    var data = obj.data;
    if (obj.event === 'detail') {
      var AssetClass = data.AssetClass;
      switch (AssetClass) {
        case '非标准化债权类资产':
          window.location.href = "ZCLR_FB_XQ.html";
          break;
        case '债券':
          window.location.href = "ZCLR_ZQ_XQ.html";
          break;
        case '同业存款':
          window.location.href = "ZCLR_TYCK_XQ.html";
          break;
        case '同业存单':
          window.location.href = "ZCLR_TYCD_XQ.html";
          break;
        case '回购':
          window.location.href = "ZCLR_HG_XQ.html";
          break;
      }
    }
  });

});
// AssetCode  资产代码  

var vm = new Vue({
  el: '#app',
  data: {
    AssetClass: '0',
    CompanyName: '',
    AssetName: '',
    ArrData: [],
    totalVisible: false,
    tableIns: [],
    defaultData: []
  },
  mounted: function () {
    this.init()
  },
  methods: {
    init: function () {
      localStorage.setItem('navigation','<a href="#">首页</a><span lay-separator="">/</span><a href="">大类资产配置模型</a><span lay-separator="">/</span><a><cite>可投资资产清单</cite></a>');
      this.defaultData = this.tableIns;
      var arry = [
        "1;FB12345678-A1;非标资产A2;非标准化债权类资产;企业A;100,000;100,000",
        "2;ZQ12345678-A2;债券资产A2;债券;企业A;2,000,000;600,000",
        "3;TC12345678-C1;同业存款资产C1;同业存款;同业C;400,000;400,000",
        "4;CD12345678-D1;同业存单资产D1;同业存单;同业D;1,000,000;300,000",
        "5;HG12345678-D1;回购资产D1;回购;同业D;50,000;50,000"];
      var keys = ['id', 'AssetCode', 'AssetName', 'AssetClass', 'CompanyName', 'amount1', 'amount'];
      arry.map(item => {
        var keyData = item.split(";");
        var obj = {};
        keyData.map((item, index) => {
          obj[keys[index]] = item;
        });
        this.ArrData.push(obj);
      });
      this.tableIns = this.defaultData = this.ArrData;
    },
    total: function (data) {
      var tableData = data;
     // this.totalVisible = data.length == 0 ? false : true;
    }
  }
})